home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
gfx
/
jpegaga2.lha
/
jpegAGAsrc
/
ppm2aga
/
ppm2AGA.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-04-12
|
7KB
|
296 lines
/* ppm2AGA main module */
/* written 1993-95 by Günther Röhrich */
/* This is version 1.6a */
#include <clib/exec_protos.h>
#include <clib/intuition_protos.h>
#include <clib/graphics_protos.h>
#include <intuition/intuitionbase.h>
#include <graphics/gfxbase.h>
#include <libraries/iffparse.h>
#include <iffp/ilbmapp.h>
#include <dos/dos.h>
#include <dos/dosextens.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
#ifndef __GNUC__
#include <pragmas/intuition_pragmas.h>
#include <pragmas/graphics_pragmas.h>
#include <pragmas/exec_pragmas.h>
#endif
#include "ppm2AGA.h"
#ifdef __GNUC__
#include <signal.h>
#define MYSTRCMP strcasecmp
#define MYSTRNCMP strncasecmp
#else
#define MYSTRCMP strcmp
#define MYSTRNCMP strncmp
#endif
/* externals used by this module */
extern int ppm2ilbm(char *PPMfile, ULONG Mode, int NumPlanes, ULONG MaxMem);
#ifdef AZTEC_C
extern int Enable_Abort; /* Needed to disable default CTRL-C handling */
#endif
/* globals defined in this module */
char *ver = "\0$VER: ppm2AGA 1.6a (12.4.95)";
struct Library *IntuitionBase = NULL;
struct Library *GfxBase = NULL;
struct Library *IFFParseBase = NULL;
int floyd=0; /* indicates if FS-dithering should be used */
char *ILBMfile;
char *BaseName=NULL;
int ExactColor=0; /* indicates if shifting colors is allowed */
int GfxEnable=0; /* indicate if Gfx is enabled */
int VGAenable=0; /* indicate VGA-mode */
int jpegAGA=0; /* indicate that map-file should be created */
ULONG SMR=0; /* indicate that user has chosen a screenmode */
ULONG SMR_DisplayID; /* this variable contains later the DisplayID */
ULONG SMR_NumPlanes;
ULONG SMR_HAM;
struct Process *MyProcess=NULL;
void PLError(char *ErrorString); /* prints the message, cleans up and quits */
void PLExit(int returnvalue); /* cleans up and quits */
void pm_message(char* format, ... );
int AbortCheck(void);
void PLProgress(ULONG Value, ULONG MaxValue);
#ifdef __GNUC__
int GCCabort=0;
/* this is called when CTRL-C occurs */
void GCCAbortHandler(void)
{
GCCabort=1;
}
#endif
void PLUsage(void)
{
PLError("Usage: ppm2AGA infile outfile [switches]\n"
"switches: -HAM8 use HAM8-conversion (default)\n"
" -HAM6 use HAM6-conversion\n"
" -CMAPn use COLORMAP conversion with n bitplanes\n"
" -E use exact colors (only COLORMAP mode)\n"
" -FS enable Floyd-Steinberg dithering\n"
" -Mx load pictures up to size x into memory\n"
" -2 enable 2-pass processing for HAM mode\n"
" -D display picture during processing\n"
" -VGA use VGA screenmode\n"
" -SMR use screen mode requester\n"
" -jpegAGA create colormap file for jpegAGA/PhotoCDAGA\n"
" -b name base name for PhotoCDAGA map files\n");
}
main(int argc, char *argv[])
{
int Error;
int i;
ULONG Mode=HAM8;
int NumPlanes = 63;
int Pass = 1; /* 2-pass disabled by default */
ULONG MaxMem = 1000000;
#ifdef AZTEC_C /* Disable Aztec C CTRL-C handling */
Enable_Abort = 0;
#endif
#ifdef __GNUC__ /* Modify GNU C CTRL-C handling */
signal(SIGINT, GCCAbortHandler);
#endif
puts("ppm2AGA V1.6a written by Günther Röhrich.");
/* remove the comments for beta versions */
/* puts("Preliminary version. DO NOT SPREAD IT!"); */
/* Open all the libraries we need */
if(!(IntuitionBase = OpenLibrary((UBYTE *)"intuition.library", 33)))
PLError("Can't open intuition.library V33 or higher.\n");
if(!(GfxBase = OpenLibrary((UBYTE *)"graphics.library",33)))
PLError("Can't open graphics.library V33 or higher.\n");
/* iffparse.library V37 works also with Kickstart 1.2/1.3 */
if(!(IFFParseBase = OpenLibrary((UBYTE *)"iffparse.library",36)))
PLError("Can't open iffparse.library V36 or higher.\n");
/* disable system requesters for our process*/
MyProcess = (struct Process *)FindTask(NULL);
if(MyProcess) MyProcess->pr_WindowPtr = (APTR)(-1);
if(argc < 3) PLUsage();
for(i=3; i<argc; i++)
{
#ifndef __GNUC__
strupr(argv[i]);
#endif
if(!MYSTRNCMP(argv[i], "-HAM8", 5))
{
Mode = HAM8;
NumPlanes = 63;
}
else if(!MYSTRNCMP(argv[i], "-HAM6", 5))
{
Mode = HAM6;
NumPlanes = 15;
}
else if(!MYSTRNCMP(argv[i], "-CMAP", 5))
{
Mode = COLORMAP;
NumPlanes = (int)strtoul(&argv[i][5], NULL, 0);
if(NumPlanes < 1 || NumPlanes > 8)
PLError("Only 1 to 8 planes allowed.\n");
}
else if(!MYSTRNCMP(argv[i], "-M", 2))
{
MaxMem = strtoul(&argv[i][2], NULL, 0);
}
else if(!MYSTRNCMP(argv[i], "-FS", 3))
{
floyd = 1;
}
else if(!MYSTRNCMP(argv[i], "-E", 2))
{
ExactColor = 1;
}
else if(!MYSTRNCMP(argv[i], "-D", 2))
{
GfxEnable = 1;
}
else if(!MYSTRNCMP(argv[i], "-2", 2))
{
Pass = 0;
}
else if(!MYSTRNCMP(argv[i], "-VGA", 4))
{
VGAenable = 1;
}
else if(!MYSTRNCMP(argv[i], "-SMR", 4))
{
SMR = 1;
}
else if(!MYSTRNCMP(argv[i], "-JPEGAGA", 8))
{
jpegAGA = 1;
}
else if(!MYSTRNCMP(argv[i], "-b", 2))
{
if(argc == i+1) PLUsage(); /* last argument */
BaseName = argv[i+1];
i++;
}
else PLUsage();
if( (jpegAGA == 1) && (Pass == 0 || Mode != HAM8)) PLUsage();
}
if(SMR)
{
if(ChooseScreenMode()) PLError("No screen mode selected.\n");
if(SMR_HAM)
{
if(SMR_NumPlanes == 8)
{
Mode = HAM8;
NumPlanes = 63;
}
else
{
Mode = HAM6;
NumPlanes = 15;
}
}
else
{
Mode = COLORMAP;
NumPlanes = SMR_NumPlanes;
}
}
ILBMfile = argv[2];
if(Mode == HAM8 || Mode == HAM6) NumPlanes = NumPlanes + Pass;
Error = ppm2ilbm(argv[1], Mode, NumPlanes, MaxMem);
/* if(Error) pm_message("Error, no picture created.\n"); */
PLExit(Error);
}
void PLError(char *ErrorString)
{
pm_message(ErrorString);
PLExit(10);
}
/* NOTE: if you want to implement a GUI you only have to */
/* change the functions below, not the complete program */
/* this is called on exit */
void PLExit(int returnvalue)
{
if(IntuitionBase) CloseLibrary(IntuitionBase);
if(GfxBase) CloseLibrary(GfxBase);
if(IFFParseBase) CloseLibrary(IFFParseBase);
if(MyProcess) MyProcess->pr_WindowPtr = (APTR)0;
exit(returnvalue);
}
/* this is called to see if we must abort */
int AbortCheck(void)
{
#ifndef __GNUC__
return SetSignal(0L,0L)&SIGBREAKF_CTRL_C;
#else
return GCCabort;
#endif
}
/* this is called for progress reports */
/* not called in this version */
void PLProgress(ULONG Value, ULONG MaxValue)
{
/* we do nothing special right now */
printf("\015Progress: %5.2f%%", Value * 100.0 / (MaxValue + 1));
}
/* this is called when a message must be printed */
void pm_message(char* format, ... )
{
va_list args;
va_start( args, format );
vprintf(format, args );
va_end( args );
}